package http_validation

import (
	"regexp"

	"github.com/go-playground/validator/v10"
)

// Validation 是否必填参数校验
func Validation(arbitrarily any) error {
	validate := validator.New()
	err := validate.Struct(arbitrarily)
	if err != nil {
		return err
	} else {
		return nil
	}
}

// ValidationMobile 手机号验证
func ValidationMobile(mobile string) bool {
	matched := regexp.MustCompile(`^1[356789]\\d{9}$`)
	if ok := matched.MatchString(mobile); ok {
		return true
	} else {
		return false
	}
}

// ValidationEmail 邮箱验证
func ValidationEmail(meail string) bool {
	regex := regexp.MustCompile(`^[w.-]+@[a-zA-Z0-9]+.[a-zA-Z]{2,4}$`)
	return regex.MatchString(meail)
}
